package org.aileen.springbook.model;

import lombok.Data;
import org.aileen.springbook.enums.ResultCodeEnum;

@Data
public class Result<T> {
    private ResultCodeEnum code;
    private String errMsg;
    private T data;

  //将登录和未登录的状态码和信息封装到Result对象中

    //用户未登录
    public static <T> Result<T> nologin(){
        //用户未登录
        Result result = new Result();
        result.setCode(ResultCodeEnum.NOLOGIN);
        result.setErrMsg("用户未登录");
        return result;
    }

    //用户登录成功
    public static <T> Result <T>success(T data){
        //已登录
        Result result = new Result();
        result.setCode(ResultCodeEnum.SUCCESS);
        result.setData(data);
        result.setErrMsg("");
        return result;
    }


    public static <T> Result<T> fail(String errMsg){
        //失败时
        Result result = new Result<>();
        result.setErrMsg(errMsg);
        result.setCode(ResultCodeEnum.FAIL);
        result.setData(null);
        return result;
    }

}
